package com.wo56.pushmsgcenter.business.exe;

import java.util.Iterator;

import com.framework.components.redis.RedisHelper;
import com.framework.components.redis.RemoteCacheUtil;
import com.framework.core.inter.HttpFrameWork;
import com.framework.core.pushmsgcenter.util.PushMsgConst;
import com.wo56.pushmsgcenter.business.redis.RedisMsgPubSubListener;
import com.wo56.pushmsgcenter.common.exe.TestRedisClient;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.ShardedJedis;

public class StartConsumerServer {

	public static void main(String[] args) throws Exception {
		//批量走http？少量走redis？
		if(PushMsgConst.SendType.HTTP.equals(PushMsgConst.SEND_TYPE)){
			String[] param = { "HTTP_APP_01" };
			HttpFrameWork work = new HttpFrameWork();
			work.main(param);
		} else if(PushMsgConst.SendType.REDIS.equals(PushMsgConst.SEND_TYPE)){
			Jedis jedis = null;
			if(RedisHelper.getInstance().isShared()){
				ShardedJedis shardedJedis = (ShardedJedis) RedisHelper.getInstance().getJedis();
				Iterator it = shardedJedis.getAllShards().iterator();
				//分片的话拿第1台做消息服务
				jedis = (Jedis) it.next();
			}else{
				jedis = (Jedis) RedisHelper.getInstance().getJedis();
			}
			jedis.subscribe(new RedisMsgPubSubListener(), PushMsgConst.REDIS_CHANNEL);
		} else {
			throw new Exception("不支持的方式");
		}
		
	}

}
